<?php
	session_start();

	include("site/pre_header.php");
?>
<body>
<div id="main">
	<?php
        include("site/header.php");
		echo '<div id="allcontents">';
        include("site/sideleft.php");
        include("site/sideright.php");
		$content_id = '';
		$content_title = '';

	if(isset($_GET['content_type']))
	{
		if(isset($_GET['type']))
			echo '<div class="content">';
		else
			echo '<div id="content" class="content">';
		$content_type 	= $_GET['content_type'];
		if($content_type == 'announcement' || $content_type == 'business')
		{
			if(isset($_GET['content_id']) && isset($_GET['content_title']))
			{
				$content_id		= $_GET['content_id'];
				$content_title	= $_GET['content_title'];
				$url	= "site/class/controller.php?type=content&method=getPost&content_type=$content_type&id=$content_id";
			}
		}
		else
		{
			if(isset($_GET['content_id']) && isset($_GET['content_title']))
			{
				$search_type	= $_GET['content_id'];
				$keyword	= $_GET['content_title'];
				$url 		= "site/class/controller.php?type=content&method=getResults&content_type=search&search_type=$search_type&keyword=$keyword";
			}
		}
	}
?>
    <?php
		if(isset($_GET['type']))
		{
			$type = $_GET['type'];
			if($type == 'edit')
			{
				$content_type 	= $_GET['content_type'];
				$id 	= $_GET['id'];
				
				if($content_type == 'user')
					include('site/forms/signup.php');
				else
					include('site/forms/new'.ucwords($content_type).'.php');
			}
			else if($type == 'new')
			{
				$content_type 	= $_GET['content_type'];
				
				if($content_type == 'user')
					include('site/forms/signup.php');
				else
					include('site/forms/new'.ucwords($content_type).'.php');
			}
		}
		if(isset($_GET['my']))
		{
			echo '<div class="content">';
			require_once("site/class/utility.php");
			$uid = $_GET['uid'];
			$type = $_GET['my'];
			$posts = utility::getUserPosts($type,$uid);
			echo '<div id="'.$type.'" class="highlight">';
			echo '<h3 align="center">My '.ucwords($type).'s</h3><br/>';
			if($posts != null)
			{
				foreach($posts as $post)
				{
					?>
					<div class="highlights">
	                    <div id="action">
                            <a target="_blank" href="<?php echo 'content.php?type=edit&content_type='.$type.'&id='.$post['id'];?>"><img class="action" src="site/images/edit.gif"/></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <a href="javascript:void(0);" onClick="action('delete',<?php echo '\''.$type.'\','.$post['id'];?>)" title="delete" ><img class="action" src="site/images/delete.gif"/></a><br>
                        </div>
						<img class="thumbnail" src="<?php echo $post['image'];?>" >
						<h3 id="title">
                           	<a  title="View Post" href="<?php echo $post['urls'].$post['id'].'-'.str_replace(' ','_',$post['name']).'.php';?>" target="_blank"><?php echo ucwords(substr($post['name'],0,50));?></a>
                        </h3>                         
						<p class="description"><?php echo substr($post['description'],0,150).'...';?></p>
					</div>
					<?php
				}
			}
			else
			{
				echo '<p align="center" style="color:grey;">You Have No Posts. Please create one.</p>';
			}
			echo '</div>';
		}
	?>
    </div>

<?php
		echo '</div>';
        include("site/footer.php");
    ?>
</div>
<body>
</body>
</html>
<script type="text/javascript">
	$(document).ready(function(){
		$("div#content").load("<?php echo $url;?>");
	});
</script>